package example.dao;

import example.entity.Goods;
import example.entity.Goodstype;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface GoodsMapper {
  @Results({
          @Result(column = "tID", property = "goodstype", javaType = Goodstype.class,
                  one = @One(select = "example.dao.GoodstypeMapper.querBytID"))

          })
           @Select("select * from goods")
           ArrayList<Goods> queryAll();


           @Delete("delete from goods where gdId = #{id}")
           int deleteById(Integer id);

           @Select("select *from goods where gdID = #{id}")
           Goods findById(Integer id);

           @Update("UPDATE goods SET" +
                   " tID = #{goods.tid},"+
                   "gdCode = #{goods.gdcode}, " +
                   "gdName = #{goods.gdname}," +
                   "gdPrice = #{goods.gdprice}," +
                   "gdQuantity = #{goods.gdquantity}, " +
                   "gdCity = #{goods.gdcity}, " +
                   "gdInfo = #{goods.gdinfo}, " +
                   "gdHot =  #{goods.gdhot} " +
                   "WHERE gdID =  #{goods.gdid}")
    int update(@Param("goods")Goods goods);

    @Insert("INSERT INTO goods" +
            "(tID,gdCode,gdName,gdPrice,gdQuantity,gdCity,gdInfo)" +
            "VALUES(#{goods.tid},#{goods.gdcode},#{goods.gdname},#{goods.gdprice}" +
            ",#{goods.gdquantity},#{goods.gdcity},#{goods.gdinfo})"
            )
    int insert(@Param("goods") Goods goods);



}
